package com.example.gpstracking;
import java.io.*;
import java.net.*;
public class Client_Socket
{
		int b;
		Socket s = null;
		public Socket getS() {
			return s;
		}

		PrintWriter out= null;
		BufferedInputStream in = null;
		BufferedOutputStream f = null;
		InputStream inputstream;
		String host = "IP DES SERVER RECHNERS"; // z.B.: 172.20.10.2 oder 192.168.2.xxx
		int port = 58100;
		public Client_Socket(){
			try {
				s= new Socket(host, port);
				
		
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.out.println("fehler");
			}
		}
		public void sendAdress(String address){
			try {
				out = new PrintWriter(new BufferedOutputStream(s.getOutputStream()));
				out.println("luck");
				out.println(address);
				out.flush();
				
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	public void send(InputStream inputstream){
			this.inputstream = inputstream; 
		
		try {	
			out = new PrintWriter(new BufferedOutputStream(s.getOutputStream()));
			BufferedReader myreader = new BufferedReader(new InputStreamReader(inputstream));
//			while (myreader.read() > 0){
				//out.println("rotz");
				out.println(myreader.readLine());
//				}
			
			System.out.println("Senden von GPSDaten");
			out.flush();
			
		}
		catch (Exception e){System.err.println(e);}
		finally {
			try{
				if (out != null) out.close();
				if (in != null) in.close();
				if (s != null) s.close();
			}
			catch (Exception e){}
		}
	}

	public boolean isenabled() {
		// TODO Auto-generated method stub
		if (s.isConnected()) return true;
		else return false;
	}
	
	
}
